package com.flymobi.admin;

import com.flymobi.fw.modules.SM;
import com.flymobi.fw.util.StringUtil;
import com.flymobi.po.Manager;
import com.flymobi.service.ManagerService;
import com.flymobi.util.C;
import com.flymobi.util.ManagerUtil;
import com.flymobi.util.WebContext;

/**
 * 
 * 
 * Title:
 * 
 * Description:
 * 
 * Copyright: Copyright (c) 2008
 * 
 * @author haoxz11
 * @created Oct 29, 2008 5:10:42 PM
 * @version $Id: LoginAction.java,v 1.1 2010/04/09 03:27:15 airsou Exp $
 */
public class LoginAction extends BaseAction {

	/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;
	private static final ManagerService managerService = SM
			.ManagerService;
	private String name;
	private String pass;
	private String url;
	private String cmd;
	private String code;

	@Override
	public String process(WebContext context) {
		if ("out".equals(cmd)) {
			ManagerUtil.outLogin(context);
			return "redirectindex";
		}
		if (!StringUtil.isEmpty(name) && !StringUtil.isEmpty(pass)
				&& !StringUtil.isEmpty(code)) {
			if (code.toUpperCase().equals(
					context.getClientValue("vcode").toUpperCase())) {
				Manager mb = managerService.find(name, pass);
				if (mb != null&&mb.getStatus()==1) {
					ManagerUtil.setLogin(context, mb);
					context.put("rmsg", C.TEXT.LOGIN_SUCCESS);
					if (!StringUtil.isEmpty(url)) {
						return url;
					} else {
						return "redirectindex";
					}
				} else {
					context.put("emsg", C.TEXT.LOGIN_FAIL);
				}
			} else {
				context.put("emsg", C.TEXT.LOGIN_CODE_ERROR);
			}
		} else {
			if (StringUtil.isEmpty(name)) {
				context.put("emsg", C.TEXT.LOGIN_NAME_NULL);
			}else if (StringUtil.isEmpty(pass)) {
				context.put("emsg", C.TEXT.LOGIN_PASS_NULL);
			}else if (StringUtil.isEmpty(code)) {
				context.put("emsg", C.TEXT.LOGIN_CODE_NULL);
			}
		}
		if (url != null) {
			context.put("url", url);
		}
		return "index";
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPass() {
		return pass;
	}

	public void setPass(String pass) {
		this.pass = pass;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getCmd() {
		return cmd;
	}

	public void setCmd(String cmd) {
		this.cmd = cmd;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

}
